package com.springboot.config;

import com.google.common.base.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.api.sharding.ShardingValue;
import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;
import org.apache.tomcat.util.buf.StringUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * @Author: TongRui乀
 * @Date: 2019-12-30 14:08
 * @description：
 */
@Slf4j
public class DbAlgorithm implements HintShardingAlgorithm {

    private String db = "db";

    public DbAlgorithm(){}

    @Override
    public Collection<String> doSharding(Collection collection, HintShardingValue hintShardingValue) {

        log.info("collection");

        collection.forEach(value ->{
            log.info("{}",value);
        });

        ArrayList<String> strings = new ArrayList<>();

        Collection values = hintShardingValue.getValues();

        values.forEach(value->{
            strings.add(db + value);
        });

        return strings;
    }
}
